from dataclasses import dataclass

@dataclass
class Sniffer:
    def sniff(self, header: bytes) -> bool:
        pass

@dataclass
class PrefixSniffer(Sniffer):
    prefix: bytes

    def sniff(self, header: bytes) -> bool:
        return header.startswith(self.prefix)

image_mimes = {
    "image/jpeg": PrefixSniffer(b'\xFF\xD8\xFF'),
    "image/png": PrefixSniffer(b'\x89PNG\r\n\x1A\n'),
    "image/bmp": PrefixSniffer(b'BM'),
    "image/webp": PrefixSniffer(b'RIFF'),
    "image/gif": PrefixSniffer(b'GIF8'),
}

def image_mime(header: bytes) -> tuple[str, bool]:
    for ext, sniffer in image_mimes.items():
        if sniffer.sniff(header):
            return ext, True
    return "", False

def image_extension(header: bytes) -> tuple[str, bool]:
    ext, ok = image_mime(header)
    if not ok:
        return "", False
    return "." + ext[6:], True
